package name.fowler.refactoring.simplestore;

import name.fowler.refactoring.simplestore.domain.Movie;
import name.fowler.refactoring.simplestore.domain.Rental;

public class PriceCalculator extends Calculator {
	private int paramDays;
	private double paramPrice;
	
	public void calculateWhenPriceCodeChildren() {
		int days = this.paramDays;
		double price = 1.5;
		if (days > 3) {
			price = (days - 3) * 1.5;
		}
		this.paramPrice = price;
	}
	
	public void calculateWhenPriceCodeRegular() {
		int days = this.paramDays;
		double price = 2;
        if (days > 2) {
            price += (days - 2) * 1.5;
        }
        this.paramPrice = price;
	}

	public void calculateWhenPriceCodeNewRelease() {
		int days = this.paramDays;
		double price = days * 3;
		this.paramPrice = price;
	}
	
	public double getPrice(Movie movie, int days)
	{
		this.paramPrice = 0;
		this.paramDays = days;
		movie.getPriceCode().accept(this);
		return this.paramPrice;
	}
	
	public double getPrice(Rental rental)
	{
		double sum = 0;
		for (Movie movie : rental.getMovies()) {
			sum += this.getPrice(movie, rental.getDaysRented());
		}
		return sum;
	}
}
